package cc.yugu.yhdw.webserver.web.controller.security.basic;

import cc.yugu.yhdw.common.annotation.ViewModel;
import cc.yugu.yhdw.common.constant.ConstEnum;
import cc.yugu.yhdw.common.entity.AreaCache;
import cc.yugu.yhdw.common.entity.json.DataResult;
import cc.yugu.yhdw.common.entity.json.ExtResult;
import cc.yugu.yhdw.webserver.service.basic.AreaService;
import cc.yugu.yhdw.webserver.web.controller.security.SecurityController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
/**
 * 地区控制器
 * 
 * @Date:Created in 2018/7/17 11:36
 * @Author:
 * @Modified By: zjn 2018/7/17 11:36
 */ 
@Controller
@RequestMapping(value = "/security/basic/area")
public class AreaController extends SecurityController {

    @Autowired
    AreaCache areaCache;
    @Autowired
    AreaService areaService;
    /**
    * 返回到 show_area.ftl页面
    * 
    * @Param: []
    * @Return: void
    * @Author By: zjn 2018/7/17  11:36
    */ 
    @RequestMapping(value = "show_area.htm")
    public void showArea() {
    }
    /**
    * 得到地址信息
    * 
    * @Param: [id]
    * @Return: cc.yugu.yhdw.common.entity.json.ExtResult
    * @Author By: zjn 2018/7/17  11:52
    */ 
    @ResponseBody
    @RequestMapping(value = "children.htm")
    public ExtResult children(int id) {
        return DataResult.successResult(areaCache.getChildren(id));
    }
    /**
    * 输出JSON格式的地址信息到async_tree.ftl显示
    * 
    * @Param: [dummy, id, response]
    * @Return: void
    * @Author By: zjn 2018/7/17  13:14
    */ 
    @ResponseBody
    @ViewModel(ViewModel.JSON_ARRAY)
    @RequestMapping(value = "async_tree.htm")
    public void asyncTree(String dummy, String id, HttpServletResponse response) throws Exception {
        response.setContentType(ConstEnum.ContentType.JSON.getValue());
        areaService.children(dummy, id, response.getOutputStream());
    }
}
